Skip to content

Conversation

@GlenDC
Copy link
Collaborator

@GlenDC GlenDC commented Jul 15, 2025

This PR adds the RAII chapter for the idiomatic Rust deep dive.

@google-cla
Copy link

google-cla bot commented Jul 15, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Collaborator

@randomPoison randomPoison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, there's lots of good stuff in this chapter 😁 I've got various feedback below, but it's definitely off to a good start!

@GlenDC
Copy link
Collaborator Author

GlenDC commented Jul 25, 2025

I started to action all feedback since today. I'll explicitly re-request reviews once I am done. Probably best not to review again until then.

@GlenDC GlenDC added the waiting for author Waiting on the issue author to reply label Jul 25, 2025
GlenDC added 4 commits July 26, 2025 15:11
- directly where possible
- otherwise as inline feedback as notes to take
  into account for next draft
refresher on `RAII` and
use the OS File Descriptor example to start
the discussions around RAII

all previous content is for now moved to `_old` for my own
reference, will add the new content based on the agreed upon
new structure next.
@GlenDC GlenDC marked this pull request as draft August 1, 2025 08:00
@GlenDC GlenDC removed the waiting for author Waiting on the issue author to reply label Aug 3, 2025
@GlenDC GlenDC marked this pull request as ready for review August 3, 2025 19:34
@GlenDC
Copy link
Collaborator Author

GlenDC commented Aug 3, 2025

The four slides in the RAII chapter are ready for review again.

Copy link
Collaborator

@randomPoison randomPoison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking pretty good. The drop bomb and scope guard slides look good to me, my biggest suggestion is that we might want to split the mutex slide up so that it flows a bit better.

Copy link
Collaborator

@djmitche djmitche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a brief look at the updates since my last comments, and I'm happy enough!

@GlenDC
Copy link
Collaborator Author

GlenDC commented Aug 30, 2025

@randomPoison your feedback was all address as far as I know. Ready for another round of reviews.

Copy link
Collaborator

@randomPoison randomPoison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my previous feedback! I've looked over things again and still have some suggestions/requests for how this can be improved. There's a couple of places where I've suggested adding new slides:

  • Splitting out the discussion of when drop does and doesn't run.
  • Using mem::forget to defuse drop bombs.
  • Using Option for cases where you need to transfer ownership in drop.

I'm fine with those being split into a separate PR if you want to get this one landed, though if you do that then it'd be good to open an issue tracking the unfinished changes to this section.

<https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#169-196>

- If both `drop()` and `close()` exist, the file descriptor may be released
twice. To avoid this, remove `close()` and rely solely on `Drop`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like more explicit instructions for the speaker about how the code should evolve up to this point, and how to demonstrate this. In particular the order in which the instructor should add the drop method, remove the close method, how to demonstrate the double-closing of the file etc. The flow can get very messy during the actual presentation if we don't think this through ahead of time.

- If a destructor itself panics during unwinding, the program aborts
immediately.
- If the program exits with `std::process::exit()` or is compiled with the
`abort` panic strategy, destructors are skipped.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good information, but it is not made actionable for the listener. Quoting my original comment:

It is a good tie-in to discuss use cases for drop: it is good for cleaning up things within the scope of a process, but not the right tool for guaranteeing that something happens outside of the process (e.g., on local disk, or in another service in a distributed system).

For example, it is a bad idea to rely exclusively on drop to clean up temporary files: if the program terminates in a way that skips running drop, temporary files will persist, and eventually the computer will run out of space. This can happen if the program crashes or leaks the value whose drop is responsible for deleting the file. In addition to a drop implementation within the program, one also needs a classic unix-style temp file reaper that runs as a separate process.

I suggest adding an example like that to the speaker notes. Otherwise the information "drop is not run when the program exits" is not connected to any real-world bad outcome / architectural mistake.

@gribozavr
Copy link
Collaborator

gribozavr commented Sep 21, 2025

@GlenDC Thank you for the updates! Please see my latest round of comments. There are a lot of comments, but I tried to make them actionable. Please pay particular attention to the requests to split the slides. Looking forward to seeing the revised section, I think this PR is getting closer and closer to being finalized.

@gribozavr gribozavr added the waiting for author Waiting on the issue author to reply label Sep 21, 2025
@google google deleted a comment from gribozavr Nov 30, 2025
@google google deleted a comment from gribozavr Nov 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deep_dives/idiomatic waiting for author Waiting on the issue author to reply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants